package com.qmhl.toolposition.activity

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import com.qmhl.toolposition.adapter.ChapterAdapter
import com.qmhl.toolposition.base.BaseActivity
import com.qmhl.toolposition.bean.Chapter
import com.qmhl.toolposition.bean.ChapterItem
import com.qmhl.toolposition.databinding.ActivityPositionOtherSettingHelperBinding
import com.qmhl.toolposition.databinding.DialogVivo10Binding
import com.qmhl.toolposition.databinding.DialogVivo11Binding
import com.qmhl.toolposition.databinding.DialogVivo8Binding
import com.qmhl.toolposition.databinding.DialogVivo9Binding


class PositionOtherSettingHelperActivity : BaseActivity() {

    lateinit var binding: ActivityPositionOtherSettingHelperBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityPositionOtherSettingHelperBinding.inflate(layoutInflater)
        setContentView(binding.root)
    }


    override fun initListener() {
        super.initListener()
        binding.ivBack.setOnClickListener {
            finish()
        }

    }


    override fun initData() {
        super.initData()

        setExpandListView()

    }

    private fun setExpandListView() {


        var dataList = getDataList()
        val chapterAdapter = ChapterAdapter(this, dataList)
        binding.expandListView.setAdapter(chapterAdapter)


        //设置子选项被点击监听事件
        binding.expandListView.setOnChildClickListener { parent, view, groupPosition, childPosition, id ->
            var paren = dataList[groupPosition].name
            var chil = dataList[groupPosition].list[childPosition].name
            if (paren == "vivo") {
                if (chil == "8.0设置教程") {
                    showVivoDialogBy_80()
                } else if (chil == "9.0设置教程") {
                    showVivoDialogBy_90()
                } else if (chil == "10.0设置教程") {
                    showVivoDialogBy_10()
                } else if (chil == "11设置教程") {
                    showVivoDialogBy_11()
                }
            } else if (paren == "oppo") {

            } else if (paren == "华为") {

            } else if (paren == "小米") {

            }

//            startHelperActivity()
            false
        }

        //设置分组选项被点击监听事件
        binding.expandListView.setOnGroupClickListener { parent, view, groupPosition, id ->
            false
        }


        //设置折叠时的监听事件
        binding.expandListView.setOnGroupCollapseListener { groupPosition -> {} }


        //设置展开时的监听事件
        binding.expandListView.setOnGroupExpandListener { groupPosition ->

            for (i in 0 until chapterAdapter.groupCount) {
                //不是当前选中的全部收起
                if (groupPosition != i) {
                    binding.expandListView.collapseGroup(i);
                }

            }
        }
    }

    private fun startHelperActivity(title: String, url: String) {


        var intent = Intent(this, PositionHelpWebViewActivity::class.java).apply {
            putExtra("url", url)
            putExtra("title", title)
        }
        startActivity(intent)
    }

    fun getDataList(): MutableList<Chapter> {
        var dataList = mutableListOf<Chapter>()
        var c1 = Chapter(
            "vivo",
            mutableListOf(
                ChapterItem("8.0设置教程"),
                ChapterItem("9.0设置教程"),
                ChapterItem("10.0设置教程"),
                ChapterItem("11设置教程")
            )
        )
        var c2 = Chapter(
            "oppo",
            mutableListOf(
                ChapterItem("7.0设置教程"),
                ChapterItem("8.0设置教程"),
                ChapterItem("9.0设置教程"),
                ChapterItem("10.0设置教程"),
                ChapterItem("11设置教程"),
                ChapterItem("12设置教程")
            )
        )
        var c3 = Chapter(
            "华为",
            mutableListOf(
                ChapterItem("7.0设置教程"),
                ChapterItem("8.0设置教程"),
                ChapterItem("9.0设置教程"),
                ChapterItem("鸿蒙2.0.0设置教程")
            )
        )
        var c4 = Chapter(
            "小米",
            mutableListOf(
                ChapterItem("7.0设置教程"),
                ChapterItem("8.0设置教程"),
                ChapterItem("9.0设置教程"),
                ChapterItem("10.0设置教程"),
                ChapterItem("11设置教程")
            )
        )


        dataList.add(c1)
        dataList.add(c2)
        dataList.add(c3)
        dataList.add(c4)
        return dataList
    }

    private fun showVivoDialogBy_80() {
        val binding: DialogVivo8Binding = DialogVivo8Binding.inflate(layoutInflater)
        val dialog = AlertDialog.Builder(this).run {
            setCancelable(true)
            setView(binding.root)
            create()
        }
        dialog.show()

        binding.tvBattery.setOnClickListener {
            startHelperActivity(
                "电池设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_dianci_8.0.html"
            )
        }
        binding.tvAddLock.setOnClickListener {
            startHelperActivity(
                "加锁设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_jiasuo_8.0.html"
            )
        }
        binding.tvStart.setOnClickListener {
            startHelperActivity(
                "自启动",
                "file:///android_asset/position_helper/vivo8.0/vivo_ziqidong_8.0.html"
            )
        }
        binding.tvWlan.setOnClickListener {

        }

    }

    private fun showVivoDialogBy_90() {
        val binding: DialogVivo9Binding = DialogVivo9Binding.inflate(layoutInflater)
        val dialog = AlertDialog.Builder(this).run {
            setCancelable(true)
            setView(binding.root)
            create()
        }
        dialog.show()

        binding.tvBattery.setOnClickListener {
            startHelperActivity(
                "电池设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_dianci_8.0.html"
            )
        }
        binding.tvAddLock.setOnClickListener {
            startHelperActivity(
                "加锁设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_jiasuo_8.0.html"
            )
        }
        binding.tvStart.setOnClickListener {
            startHelperActivity(
                "自启动",
                "file:///android_asset/position_helper/vivo8.0/vivo_ziqidong_8.0.html"
            )
        }


    }

    private fun showVivoDialogBy_10() {
        val binding: DialogVivo10Binding = DialogVivo10Binding.inflate(layoutInflater)
        val dialog = AlertDialog.Builder(this).run {
            setCancelable(true)
            setView(binding.root)
            create()
        }
        dialog.show()

        binding.tvBattery.setOnClickListener {
            startHelperActivity(
                "电池设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_dianci_8.0.html"
            )
        }
        binding.tvAddLock.setOnClickListener {
            startHelperActivity(
                "加锁设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_jiasuo_8.0.html"
            )
        }
        binding.tvStart.setOnClickListener {
            startHelperActivity(
                "自启动",
                "file:///android_asset/position_helper/vivo8.0/vivo_ziqidong_8.0.html"
            )
        }


    }

    private fun showVivoDialogBy_11() {
        val binding: DialogVivo11Binding = DialogVivo11Binding.inflate(layoutInflater)
        val dialog = AlertDialog.Builder(this).run {
            setCancelable(true)
            setView(binding.root)
            create()
        }
        dialog.show()

        binding.tvBattery.setOnClickListener {
            startHelperActivity(
                "电池设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_dianci_8.0.html"
            )
        }
        binding.tvAddLock.setOnClickListener {
            startHelperActivity(
                "加锁设置",
                "file:///android_asset/position_helper/vivo8.0/vivo_jiasuo_8.0.html"
            )
        }
        binding.tvStart.setOnClickListener {
            startHelperActivity(
                "自启动",
                "file:///android_asset/position_helper/vivo8.0/vivo_ziqidong_8.0.html"
            )
        }


    }


}